package sys.timer;

import java.util.*;
import java.lang.*;

public class Timer
{
    public Timer()
    {
        timer = new java.util.Timer();
        interval = 0;
    }

    public void init(TimerClient tc, Object marker, long interval)
    {
        stop();
        this.tc = tc;
        this.interval = interval;
        this.marker = marker;
    }

    public void start()
    {
        timer.schedule(new ToDo(), 0, interval); 
    }

    public void stop()
    {
        timer.cancel();
    }

    private java.util.Timer timer;
    private TimerClient tc;
    private long interval;
    private Object marker;

    class ToDo extends TimerTask
    {
        public void run()
        {
            try
            {
                tc.timeout(marker);
            }
            catch(Exception e)
            {
                stop();
            }
        }
    }

}
